cmake_minimum_required(VERSION 3.15)
set(CMAKE_C_STANDARD 11)
project(CQUPT VERSION 1.0.0)

add_library(CQUPT STATIC
        src/cqupt.c
        include/cqupt.h
)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

target_include_directories(CQUPT
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
)

target_link_libraries(CQUPT
    PUBLIC
        wsock32
        ws2_32
)

# Install targets
install(TARGETS CQUPT
    EXPORT CQUPTTargets
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    RUNTIME DESTINATION bin
    INCLUDES DESTINATION include
)

# Install headers
install(FILES include/cqupt.h
    DESTINATION include
)

# Install export file
install(EXPORT CQUPTTargets
    FILE CQUPTTargets.cmake
    NAMESPACE CQUPT::
    DESTINATION lib/cmake/CQUPT
)

# Create package config file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
    "${CMAKE_CURRENT_BINARY_DIR}/CQUPTConfigVersion.cmake"
    VERSION ${PROJECT_VERSION}
    COMPATIBILITY AnyNewerVersion
)

configure_package_config_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/CQUPTConfig.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/CQUPTConfig.cmake"
    INSTALL_DESTINATION lib/cmake/CQUPT
)

install(FILES
    "${CMAKE_CURRENT_BINARY_DIR}/CQUPTConfig.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/CQUPTConfigVersion.cmake"
    DESTINATION lib/cmake/CQUPT
)

add_subdirectory(example)